//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//
#include "plMemory.h"
#include "plDatabase.h"

pl_DEFINE_CLASS(plMemory)

//Constructor
plMemory::plMemory() {

	//Indexs these three fields
	Index(&ObjectId);
	Index(&Address);
	Index(&ClassName);
	
	//Creates the database table
	CreateObject();
	
	ObjectId.Setup("ObjectId", this);
	Address.Setup("Address", this);
	ClassName.Setup("ClassName", this);
}

//Sets the object that is memory object is assotated with
void plMemory::SetObject(plObject* object) {
	
	//If object is new to the memory table ie. it's a base class
        if(object->Id() == plObject::BadId) {
		object->SetId(Id());
		ObjectId = Id();
	} else {
		//object is already in memory database ie. this is a subclass of something
		ObjectId = object->Id();
	}	
	
	//This is the current System Memory Address
	Address = (long long)object;
	
	//The name of the class
	ClassName = object->_GetClassName();
}

//Creates the plMemory object
void plMemory::CreateObject() {
	GetDatabase()->CreateMemoryObject(this);
}



